package org.bukkitmodders.copycat;

import java.util.HashMap;
import java.util.Stack;

import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkitmodders.copycat.listeners.CopyCatPlayerListener;
import org.bukkitmodders.copycat.managers.ConfigurationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Plugin extends JavaPlugin {
	// http://javadoc.lukegb.com/BukkitJD/index.html

	private final CopyCatPlayerListener playerListener = new CopyCatPlayerListener(this);
	private final Logger log = LoggerFactory.getLogger(Plugin.class);
	private final HashMap<String, Stack<Stack<RevertableBlock>>> undoBuffers = new HashMap<String, Stack<Stack<RevertableBlock>>>();
	private ConfigurationManager configurationManager;

	public void onDisable() {

		log.info("Plugin Disabled");
	}

	public void onEnable() {

		PluginManager pm = getServer().getPluginManager();

		pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this);

		getConfiguration(); // Force Lazy Load
		log.info(getDescription().getName() + " " + getDescription().getVersion() + " Enabled");
	}

	public ConfigurationManager getConfigurationManager() {

		if (this.configurationManager == null) {
			this.configurationManager = new ConfigurationManager(getDataFolder());
		}

		return this.configurationManager;
	}

	public HashMap<String, Stack<Stack<RevertableBlock>>> getUndoBuffers() {

		return undoBuffers;
	}
}